package com.kobe.algorithm.leetcode.demo;

import java.util.*;

/**
 * @author ：caopengfei
 * @date ：2021/2/27
 */
public class Demo3 {
    public List<List<Integer>> permute(int[] nums) {


        List<List<Integer>> result = new ArrayList<>();
        for(int i = 0;i < nums.length; i++){
            Map<Integer, HashSet<Integer>> position = new HashMap<>();
            List<Integer> ans = new ArrayList<>();
            ans.add(nums[i]);
            for (int j = 0; j < nums.length ; j++) {
                if(!position.containsKey(ans.size()+1)){
                    position.put(ans.size()+1,new HashSet<Integer>());
                }

                if(i == j){
                    continue;
                }
                if(position.get(ans.size()+1).contains(nums[j])){
                    continue;
                }else{
                    position.get(ans.size()+1).add(nums[j]);
                    ans.add(nums[j]);
                }
            }
            result.add(ans);
        }
        return result;
    }

    public static void main(String[] args) {
        Demo3 demo3 = new Demo3();
        int [] nums = {1,2,3};
        System.out.println(demo3.permute(nums));
    }



}
